package cn.south.campus.business.model.vo;

import cn.south.campus.business.model.entity.Complaint;
import cn.south.campus.common.model.vo.BaseVO;
import cn.south.campus.common.utils.DateUtil;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * <p>
 *
 * </p>
 *
 * @author chow
 * @since 2024/12/5 13:20
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class ComplaintVo extends BaseVO {
    /**
     * 图片
     */
    private String pic;

    /**
     * 内容
     */
    private String content;

    /**
     * 点赞数
     */
    private Long agreeCount = 0L;

    private boolean agree;

    /**
     * 点踩数
     */
    private Long rejectCount = 0L;

    private boolean reject;

    /**
     * 评论数
     */
    private Long commentCount = 0L;

    private boolean comment;

    /**
     * 用户id
     */
    private Long userId;

    /**
     * 用户头像
     */
    private String avatar;

    /**
     * 用户昵称
     */
    private String nickname;

    /**
     * 0待发布，1已发布，2已撤销
     */
    private Integer status;

    private String timeAgo;

    public static ComplaintVo convert(Complaint complaint) {
        if (complaint == null) {
            return null;
        }
        ComplaintVo complaintVo = new ComplaintVo();
        complaintVo.setId(complaint.getId());
        complaintVo.setPic(complaint.getPic());
        complaintVo.setContent(complaint.getContent());
        complaintVo.setUserId(complaint.getUserId());
        complaintVo.setStatus(complaint.getStatus());
        complaintVo.setAvatar(complaint.getAvatar());
        complaintVo.setNickname(complaint.getNickname());
        complaintVo.setTimeAgo(DateUtil.getTimeAgo(complaint.getUpdateTime()));
        complaintVo.setCreateTime(DateUtil.format(complaint.getCreateTime()));
        complaintVo.setUpdateTime(DateUtil.format(complaint.getUpdateTime()));
        return complaintVo;
    }

    public static Complaint convert(ComplaintVo complaintVo) {
        if (complaintVo == null) {
            return null;
        }
        Complaint complaint = new Complaint();
        complaint.setId(complaintVo.getId());
        complaint.setPic(complaintVo.getPic());
        complaint.setContent(complaintVo.getContent());
        complaint.setStatus(complaintVo.getStatus());
        complaint.setUserId(complaintVo.getUserId());
        return complaint;
    }
}
